package com.example.factory.api.controller;

import com.example.factory.api.dto.DtoRole;
import com.example.factory.api.dto.Response;
import com.example.factory.api.dto.form.DtoRoleForm;
import com.example.factory.api.facade.RoleFacade;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Lei Tao
 */
@RestController
@RequestMapping("/admin/role")
public class RoleController {
    private final RoleFacade roleFacade;

    public RoleController(RoleFacade roleFacade) {
        this.roleFacade = roleFacade;
    }


    @GetMapping("/list")
    public Response<List<DtoRole>> list() {
        return roleFacade.roleList();
    }

    @GetMapping("/{roleGuid}/delete")
    public Response<Void> deleteRole(@PathVariable("roleGuid") String roleGuid) {
        return roleFacade.deleteRole(roleGuid);
    }

    @GetMapping("/{roleGuid}/details")
    public Response<DtoRole> retrieveRole(@PathVariable("roleGuid") String roleGuid) {
        return roleFacade.retrieveRole(roleGuid);
    }

    @PostMapping("/save")
    public Response<DtoRole> saveOrUpdate(@RequestBody DtoRoleForm DtoRoleForm) {
        return roleFacade.saveOrUpdateRole(DtoRoleForm);
    }
}
